package cn.tedu.mall.seckill.timer.config;

import cn.tedu.mall.seckill.timer.job.SeckillBloomInitialJob;
import cn.tedu.mall.seckill.timer.job.SeckillInitialJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail initJobDetail(){
        return JobBuilder.newJob(SeckillInitialJob.class)
                .withIdentity("initSeckill")
                .storeDurably()
                .build();
    }
    @Bean
    public Trigger initSeckillTrigger(){
        CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("0 0/1 * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(initJobDetail())
                .withIdentity("initTrigger")
                .withSchedule(cron)
                .build();
    }
    @Bean
    public JobDetail seckillBloomJobDetail(){
        return JobBuilder.newJob(SeckillBloomInitialJob.class)
                .withIdentity("SeckillBloom")
                .storeDurably()
                .build();
    }
    @Bean
    public Trigger seckillBloomTrigger(){
        return TriggerBuilder.newTrigger()
                .forJob(seckillBloomJobDetail())
                .withIdentity("SeckillBloomTrigger")
                .withSchedule(CronScheduleBuilder.cronSchedule("0/30 * * * * ?"))
                .build();
    }

















}
